#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/wait.h>


int main(int argc, char* argv[])
{
  printf("process is running\n");
  pid_t id = fork();
  assert(id != -1);
  if(id == 0)
  {
    //子进程
    sleep(1);
    /*
    char *argv_[]=
    {
      "ls",
      "-a",
      "-l",
      "--color=auto",
      NULL 
    };
    */
    execvp(argv[1],&argv[1]);
    // execvp(argv[0],argv);
    /*
    char *const envp_[] = {
      (char*)"MYENV=1111222333444",
      NULL 
    };
    extern char** environ;
    putenv((char*)"MYENV=444443333222221");
    execle("./mybin","mybin",NULL,environ);
    */ 
    
    
    // execle("./mybin","mybin",NULL,envp_);

    // execl("./myshell.sh","myshell.sh",NULL);
    // execl("./mypy.py","mypy.py",NULL);
    // execl("./my_cpp","my_cpp",NULL);
    // execl("./mybin","mybin",NULL);
    // execv("/usr/bin/ls",argv_);
    // execl("/usr/bin/laaaaaas","ls","-a","-l","--color=auto",NULL);
    // execlp("ls","ls","-a","-l","--color=auto",NULL);
    exit(100);//不会执行
  }
  //父进程
  int status = 0;
  pid_t ret = waitpid(id,&status,0);
  if(ret>0)
  {
    printf("wait success...... exit code:%d,sig:%d\n",(status>>8)&0xFF,status & 0x7F);
  }
  return 0; 
}

/*
int main()
{
  printf("[process is running.....\n");
  // execl("/usr/bin/lscajsd","ls","--color=auto","-a","-l",NULL);
  execl("/usr/bin/top","top",NULL);
  perror("execl");//打印错误原因
  printf("process running done........\n");
  exit(1);
}
*/ 





